// 自定义投票插件

string author = "Live";
string pluginName = "CustomVote 自定义投票插件";
string version = "0.1";

// 当插件被初始化
void OnPluginInit()
{
	// 设置插件信息
	PluginData::SetAuthor(author);
	PluginData::SetName(pluginName);
	PluginData::SetVersion(version);

	// 提示
	ThePresident.InfoFeed("插件:"+pluginName+"| 版本:"+version+"| 作者:"+author,false);

    Events::Player::PlayerSay.Hook( @PlayerSay );

}

HookReturnCode PlayerSay(CTerrorPlayer@ pPlayer, CASCommand@ pArgs)
{
    string arg = pArgs.Arg( 1 );
	string arg1 = "";
	string arg2 = "";

	// 切分字符串(这样就可以用空格传一个命令参数了)
	int subIndex = arg.findFirst(" ",0);
	if(not (subIndex < 0)){
		arg1 = arg.substr(0,subIndex);
		arg2 = arg.substr(subIndex+1,-1);
		//Chat.PrintToChat(all,""+arg1+"|"+arg2);
	}else{
		arg1 = arg;
	}

    if( AdminSystem.AdminExist(pPlayer) ){
        if( arg1 == "!vote" && arg2 != "" ){

            ASVoteItem my_vote;

            // The player who started this vote.
            // Can be set to null, or skipped.
            my_vote.SetPlayer( pPlayer );

            // The function that will be fired if the vote was a success
            my_vote.SetFunction( VoteOutput );

            // Our vote detail information.
            // Use %s1 to show the "Details" information.
            my_vote.Name = arg2;

            // Our item we want to vote for.
            //my_vote.Details = "Sexy Waffles";

            // The string we want to display if this vote was a success
            // Use %s1 to show the "Details" information.
            my_vote.PassedString = "[插件作者：Live]";

            // Team restriction, does not apply if we have no Player.
            my_vote.AllyRestriction = true;

            // Start our vote
            Utils.StartVote( my_vote );
        }
    }
    return HOOK_CONTINUE;
}

void VoteOutput( const string &in szResult, int nYesVotes, int nNoVotes )
{
    //Chat.PrintToChat(all,szResult);
    //Chat.PrintToChat(all,""+nYesVotes);
    //Chat.PrintToChat(all,""+nNoVotes);
    //nYesVotes>nNoVotes?Chat.PrintToChat(all,"{green}投票通过"):Chat.PrintToChat(all,"{red}投票不通过");
    Chat.PrintToChat(all,"投票结果 {green}"+nYesVotes+"{white} - {red}"+nNoVotes);
}